
from google.appengine.api import memcache

import dlz_config as dc

from record import Record
from ft_table import FtTable

import model
from google.appengine.ext import db

def show_transaction(t):
    for s in t.sqlrequest_set:
        print s.sql, s.status
        
    print '-'*20
        
def test():
    tableid = 478653 # New Table
    ft = FtTable(None, None, tableid)
    
    db.delete(model.Transaction.all())
    db.delete(model.SqlRequest.all())
    t = model.Transaction()
    t.description = 'test'
    t.status = 'new'
    t.put()
    
    r = Record(ft)
    try:
        r.ft.delete_all(t)
    except:
        pass
    
    for i in range(0):
        #insert
        r = Record(ft)
        r['Text'] = 'Mel Test %s' % i
        r['ID'] = '100%s' % i
        try:
            r.insert(t)
        except:
            pass
        #update
        r['Text'] = 'Mel Test 2 %s' % i
        try:
            r.update(t)
        except:
            pass
        try:
            r.delete(t)
        except:
            pass
    t = model.Transaction()
    t.description = 'test exception'
    t.status = 'new'
    t.put()
    sql = 'delete from 1'
    try:
        ft.SqlQuery(sql, t)
    except:
        pass
    sql = 'update 478653 set abc=126'
    try:
        ft.SqlQuery(sql, t)
    except: 
        pass
    sql = 'select abc from 478653'
    try:
        ft.SqlQuery(sql)
    except: 
        pass
    
    show_transaction(t)
